package beast.app;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import junit.framework.TestCase;
import beast.core.Runnable;
import beast.util.AddOnManager;
import beast.util.Randomizer;
import beast.util.XMLParser;

public class testRunMCMC extends TestCase {
	/** number of threads used to run the likelihood beast.core **/
	static public int m_nThreads = 1;
	/** thread pool **/
	public static ExecutorService g_exec = Executors
			.newFixedThreadPool(m_nThreads);
	/** random number seed used to initialise Randomizer **/
	long m_nSeed = 127;
	/** name of SnAP specification file **/
	// String m_sFileName =
	// "/Users/kwang2/Documents/workspace/BEAST2/examples/beast2vs1/testHKY_reduced.xml";
	String m_sFileName = "/home/lear/workspace/BEAST2/examples/beast2vs1/testHKY_reduced.xml";
	/** MCMC object to execute **/
	Runnable m_runnable;

	public void testRun() throws Exception {

		// parseArgs
		AddOnManager.loadExternalJars();

		// parse xml
		Randomizer.setSeed(m_nSeed);
		m_runnable = new XMLParser().parseFile(m_sFileName);
		m_runnable.setStateFile(m_sFileName + ".state", false);

		// run MCMC
		this.runMCMC();
	}

	public void runMCMC() throws Exception {
		g_exec = Executors.newFixedThreadPool(m_nThreads);
		m_runnable.run();
		g_exec.shutdown();
		g_exec.shutdownNow();
	}
}